using System;
using System.Collections.Generic;
using System.Text;
using Habanero.Base;
using Habanero.BO;

namespace FireStarterModeller.Logic
{
    public class NonValidatingTransactionCommitter : TransactionCommitterInMemory
    {
        public NonValidatingTransactionCommitter(DataStoreInMemory dataStoreInMemory) : base(dataStoreInMemory)
        {
        }

        /// <summary>
        /// Used to decorate a businessObject in a TransactionalBusinessObject. To be overridden in the concrete 
        /// implementation of a TransactionCommitter depending on the type of transaction you need.
        /// </summary>
        /// <param name="businessObject">The business object to decorate</param>
        /// <returns>
        /// A decorated Business object (TransactionalBusinessObject)
        /// </returns>
        protected override TransactionalBusinessObject CreateTransactionalBusinessObject(IBusinessObject businessObject)
        {
            return new NonValidatingTransactionalBusinessObject(businessObject);
        }
    }

    public class NonValidatingDataAccessorInMemory : DataAccessorInMemory
    {
        public NonValidatingDataAccessorInMemory()
        {
        }

        public NonValidatingDataAccessorInMemory(DataStoreInMemory dataStore) : base(dataStore)
        {
        }

        /// <summary>
        /// Creates a TransactionCommitter for you to use to persist BusinessObjects. A new TransactionCommitter is required
        /// each time an object or set of objects is persisted.
        /// </summary>
        /// <returns>
        /// </returns>
        public override ITransactionCommitter CreateTransactionCommitter()
        {
            return new NonValidatingTransactionCommitter(_dataStore);
        }
    }

    public class NonValidatingTransactionalBusinessObject : TransactionalBusinessObject
    {
        protected internal NonValidatingTransactionalBusinessObject(IBusinessObject businessObject) : base(businessObject)
        {
        }

        /// <summary>
        ///             Indicates whether all of the property values are valid
        /// </summary>
        /// <param name="invalidReason">A string to modify with a reason
        ///             for any invalid values</param>
        /// <returns>
        /// Returns true if all are valid
        /// </returns>
        protected override bool IsValid(out string invalidReason)
        {
            invalidReason = null;
            return true;
        }

        /// <summary>
        /// returns true if there is already an object in the database with the same primary identifier (primary key)
        /// or with the same alternate identifier (alternate key)
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns>
        /// </returns>
        protected override bool HasDuplicateIdentifier(out string errMsg)
        {
            errMsg = null;
            return false;
        }

        /// <summary>
        /// Checks the underlying business object for any concurrency control errors before trying to commit to 
        /// the datasource
        /// </summary>
        protected override void CheckForConcurrencyErrors()
        {
            
        }
    }
}
